What is the value of: 12    - 4/2    +    2

A good answer might be:

12, since the expression means: 12 - 2 + 2.

Arithmetic Operators

OperatorMeaningprecedence
- unary minushighest
+ unary plushighest
* multiplicationmiddle
/ division middle
% remainder middle
+ addition low
- subtractionlow

An arithmetic operator is a symbol that asks for doing some arithmetic. As the previous question illustrates, if several operators are used in an expression, there is a specific order in which the operations are done. Operators of higher precedence will operate first. There are many operators in Java, so the following shows just a few:

In the chart, operators in the same group have equal precedence. So, for example, plus ("+") and minus ("-") have the same precedence.

The unary minus and unary plus operators are used as part of a negative or a positive number. For example, -23 means negative twenty-three. More on this later.


QUESTION 14:

What is the value of the following expressions (in each expression, do the highest precedence operator first):

78 - 12 / 4            2 + 6 / 2 - 9